package com.share.order.controller;

import com.share.common.core.context.SecurityContextHolder;
import com.share.common.core.domain.Result;
import com.share.common.core.web.controller.BaseController;
import com.share.common.core.web.domain.AjaxResult;
import com.share.common.security.annotation.InnerAuth;
import com.share.common.security.annotation.RequiresLogin;
import com.share.common.security.utils.SecurityUtils;
import com.share.order.domain.OrderInfo;
import com.share.order.service.IOrderInfoService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.weaver.loadtime.Aj;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 订单相关controller
 */
@Tag(name = "订单接口管理")
@RestController
@RequestMapping("/orderInfo")
@Slf4j
public class OrderInfoController extends BaseController {

    @Autowired
    private IOrderInfoService orderInfoService;

    //获取用户未完成订单 如正在充电的订单，未付款订单 用于小程序端调用，无路径参数
    @Operation(summary = "小程序端 获取未完成订单")
    @RequiresLogin
    @GetMapping("/getNoFinishOrder")
    public AjaxResult getNoFinishOrder(){
      log.info("获取用户未完成订单，小程序：");
      return success(orderInfoService.getNoFinishOrder(SecurityUtils.getUserId()));
    }


    //获取用户未完成订单 如正在充电的订单，未付款订单 用于远程调用，有id路径参数
    @Operation(summary = "远程调用 获取未完成订单")
    @GetMapping("getNoFinishOrder/{userId}")
    public Result<OrderInfo> getNoFinishOrder(@PathVariable Long userId){
        log.info("远程调用 获取未完成订单:{}",userId);

        OrderInfo orderInfo = orderInfoService.getNoFinishOrder(userId);

        return Result.ok(orderInfo);

    }

    //获取订单详细信息
    @Operation(summary = "获取订单详细信息")
    @GetMapping(value = "/getOrderInfo/{id}")
    public AjaxResult getOrderInfo(@PathVariable("id") Long id) {
        return success(orderInfoService.selectOrderInfoById(id));
    }
}
